﻿//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;

using ProjectBase.Core;

namespace Survey.Entity.Services
{
    public class RoleAccess : IRoleAccess
    {
        #region members
        IList<string> _deniedActions = new List<string>();
        IList<string> _grantedActions = new List<string>();
        bool _isVisible = true;
        bool _useDenied = true;
        #endregion members

        /// <summary>
        ///     The list of Actions which are allowed for this RoleName.
        ///     This list is evaluated only if the UseDenied switch is set to false.
        ///     In such a case any action contained in this list is allowed, else prohibited.
        /// </summary>
        public virtual IList<string> GrantedActions
        {
            get { return _grantedActions; }
            set
            {
                Contract.Requires(value.Is(), " GrantedActions cannot be set to null");
                _grantedActions = value;
            }
        }

        /// <summary>
        ///     The list of prohibited actions for this RoleName.
        ///     If the switch UseDenied is set to true,
        ///     then every action is allowed unless its name is not contained in this DeniedActions list
        /// </summary>
        public virtual IList<string> DeniedActions
        {
            get { return _deniedActions; }
            set
            {
                Contract.Requires(value.Is(), " DeniedActions cannot be set to null");
                _deniedActions = value;
            }
        }

        #region IRoleAccess Members
        /// <summary>
        ///     The name of the existing role (returned from the Roles provider)
        ///     which is currently evaluated.
        /// </summary>
        public virtual string RoleName { get; set; }

        /// <summary>
        ///     The name of the controller to which this instance belongs.
        /// </summary>
        public virtual string ControllerName { get; set; }

        /// <summary>
        ///     True means, that whenever the action is not in the DeniedActions list - action is allowed.
        ///     False means, that action is compared with the GrantedActions list - when is not contained, access is prohibited.
        ///     Default value is true (it means, that if the DeniedList is empty, every action is granted)
        /// </summary>
        public virtual bool UseDenied
        {
            get { return _useDenied; }
            set { _useDenied = value; }
        }

        /// <summary>
        ///     Quick setting for the whole role. True means, that write actions will be prohibited.
        ///     Also the Readonly switch will be applied to the Model.
        /// </summary>
        public virtual bool IsReadOnly { get; set; }

        /// <summary>
        ///     This switch allowes to remove some nodes or controllers from the Menu TreeView rendering
        ///     even if the user role is granted. useful for Home, CodeLists etc.
        /// </summary>
        public virtual bool IsVisible
        {
            get { return _isVisible; }
            set { _isVisible = value; }
        }

        IEnumerable<string> IRoleAccess.GrantedActions
        {
            get { return GrantedActions; }
        }

        IEnumerable<string> IRoleAccess.DeniedActions
        {
            get { return DeniedActions; }
        }
        #endregion
    }
}